package cn.com.cifi.mars.mapper.wrapper;

import cn.com.cifi.mars.entity.ReturnPlanVersionDetail;
import cn.com.cifi.mars.mapper.mars.ReturnPlanVersionDetailMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: JingYuanXiang
 * @date: 2020/11/11 19:34
 */
@Component
public class ReturnPlanVersionDetailWrapper {

    @Autowired
    private ReturnPlanVersionDetailMapper returnPlanVersionDetailMapper;

    /**
     * 获取回款计划详情列表
     * @param versionId 版本id
     * @param isDelete 是否删除
     * @return
     */
    public List<ReturnPlanVersionDetail> selectByVersionId(String versionId,int isDelete) {
        QueryWrapper<ReturnPlanVersionDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("version_id",versionId)
                .eq("is_delete",isDelete);

        return returnPlanVersionDetailMapper.selectList(queryWrapper);
    }

    /**
     * 获取回款计划详情列表
     * @param versionIdList 版本id列表
     * @param isDelete 是否删除
     * @return
     */
    public List<ReturnPlanVersionDetail> selectByVersionIdList(List<String> versionIdList,int isDelete) {
        if(CollectionUtils.isEmpty(versionIdList)){
            return new ArrayList<>();
        }
        QueryWrapper<ReturnPlanVersionDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("version_id",versionIdList)
                .eq("is_delete",isDelete);

        return returnPlanVersionDetailMapper.selectList(queryWrapper);
    }

    /**
     * 获取回款计划详情列表
     * @param versionId 版本id
     * @param groupId 组团id
     * @param isDelete 是否删除
     * @return
     */
    public List<ReturnPlanVersionDetail> selectByVersionIdAndGroupId(String versionId, String groupId,int isDelete) {
        QueryWrapper<ReturnPlanVersionDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("version_id",versionId)
                .eq("group_id",groupId)
                .eq("is_delete",isDelete)
                .orderByAsc("return_time");

        return returnPlanVersionDetailMapper.selectList(queryWrapper);
    }

}
